package com.ruihui.activity.util;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;

import com.ruihui.activity.exceprion.ManualException;
/**
 * 验证类
 * @author cf
 *
 */
public class Validate {
	/**
	 * 验证用户是否登陆
	 * @param sessionid
	 * @param redisTemplate
	 */
	public static Integer validateLogin(String sessionid, @SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {
		if (!StringUtils.isEmpty(sessionid)) {
			String ob = (String) redisTemplate.opsForValue().get(sessionid);
			Integer memberId = ob == null ? null : Integer.valueOf(ob);
			if (memberId == null) {
				throw new ManualException(2001, "用户未登录");
			}
			return memberId;
		} else {
			throw new ManualException(2001, "用户未登录");
		}
	
	}

}
